<%-- 
    Document   : CMS_address
    Created on : Nov 24, 2013, 5:09:15 PM
    Author     : BibooChung
--%>

<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.util.*" import="cart.hibernate.address.*" import="cart.*,java.net.*,java.text.*" %>
<jsp:useBean id = "manager" scope= "request" class = "cart.hibernate.address.ManageAddress" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Manage Address</h1>

        <!-- Table with integrated management -->
        <table border="2" style="border-color:black;margin-bottom:20px;">
                <tr>
                    <th>Order ID</th>
                    <th>Flat</th>
                    <th>Building and Block</th>
                    <th>District</th>
                    <th>Region</th>
                    <th>Update?</th>
                    <th>Delete?</th>
                </tr>
                <%
                    List addressList = manager.getAllAddress();
                    Iterator iter = addressList.iterator();

                    while (iter.hasNext())
                    {

                        Address address = (Address) iter.next();
                %>
                        <tr>
                            <form action="ManageAddressServlet" method="post">
                                <input type="hidden" name="addressId" value="<%= address.getOrderId() %>">
                                <td>
                                    <%= address.getOrderId() %>
                                </td>
                                <td>
                                    <input type="text" name="flat" value="<%= address.getFlat() %>" />
                                </td>
                                <td>
                                    <input type="text" name="buildingAndBlock" value="<%= address.getBuildingAndBlock() %>" />
                                </td>
                                <td>
                                    <input type="text" name="district" value="<%= address.getDistrict() %>" />
                                </td>
                                <td>
                                    <select name="region">
                                        <option value="HK" <% if(address.getRegion().equals("Hong Kong")) out.print("selected='selected'");%> >
                                            Hong Kong
                                        </option>
                                        <option value="KLN" <% if(address.getRegion().equals("Kowloon")) out.print("selected='selected'");%> >
                                            Kowloon
                                        </option>
                                        <option value="NT" <% if(address.getRegion().equals("New Territories")) out.print("selected='selected'");%> >
                                            New Territories
                                        </option>
                                    </select>
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="update">
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="delete">
                                </td>
                            </form>
                        </tr>
                <%        
                    }
                %>
                    <tr>
                        <form action="ManageAddressServlet" method="post">
                            <td>Enter new address : </td>
                            <td><input type="text" name="flat" id="flat" /></td>
                            <td><input type="text" name="buildingAndBlock" id="buildingAndBlock" /></td>
                            <td><input type="text" name="district" id="district" /></td>
                            <td>
                                <select name="region">
                                    <option value="HK">Hong Kong</option>
                                    <option value="KLN">Kowloon</option>
                                    <option value="NT">New Territories</option>
                                </select>
                            </td>
                            <td><input type="submit" name="submit" value="add"></td>
                        </form>
                    </tr>
        </table>
    </body>
</html>

